package com.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@EnableWebMvc
public class MyMvcConfig implements WebMvcConfigurer { //拦截配置

    @Autowired
    private MyInterceptor myInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) { //注册白名单
        registry.addInterceptor(myInterceptor) //注册拦截管理器
                .addPathPatterns("/**") //addPathPatterns("/**") 拦截所有请求路径
                //不拦截路径
                .excludePathPatterns("/static/**") //资源路径必须放行
                .excludePathPatterns("/i18n/**") //资源路径必须放行
                .excludePathPatterns("/templates/**") //资源路径必须放行
                //放行接口
                .excludePathPatterns("/ueUploadController/**")
                .excludePathPatterns("/test")
                .excludePathPatterns("/get/**")
                .excludePathPatterns("/update/**")
                .excludePathPatterns("/delete/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) { //注册资源白名单
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/i18n/**")
                .addResourceLocations("classpath:/i18n/");
        registry.addResourceHandler("/templates/**")
                .addResourceLocations("classpath:/templates/");
    }
}
